// shouye/teacher/teacher.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl:'',
    nickName:'',
    sexBool:'',
    
    teacherUserId:'',
    backgroundsrc: 'http://icon.tongchengyouzhi.com/background.png',
    name:'',
    sex:'',
    universty:'',
    goodat:'',
    xuanyan:'',
    geren:'',
    honor:'',
    universtyName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    var id=options.id;
    // console.log('optionsId')
     //console.log(options)
    // app.qingqiu('teacher/id',{id:id},'',this.callbackFun)
    wx.request({
      url: app.globalData.baseUrl+'teacher/id',
      method:'GET',
      data:{
        id:id
      },
      header:{
        'cookie':'JSESSIONID='+wx.getStorageSync('sessionID')
      },
      success:function(res){
        console.log(res)
        try{
          var resData = res.data.data.entityData
          var realName = resData.user.realName
          if (realName==null){
            realName=resData.user.nickName
          }
          var gender = resData.user.gender
          if(gender==0){
            gender='男'
          }else{
            gender='女'
          }
          that.setData({
            avatarUrl: resData.user.avatarUrl,
            nickName: resData.user.nickName.substring(0, 5) + '...',

            name: realName,
            sex: gender,
            universty: resData.school.name,
            goodat: resData.speciality,
            xuanyan: resData.motto,
            geren: resData.experience,
            honor: resData.honor,
            teacherUserId: resData.user.id
          })
          if (that.data.sex == '男') {
            that.setData({
              sexBool: true
            })
          } else {
            that.setData({
              sexBool: false
            })
          }
          if (that.data.universty.length > 5) {
            that.setData({
              universtyName: that.data.universty.substring(0, 5) + '...'
            })
          } else {
            that.setData({
              universtyName: that.data.universty
            })
          }
        }catch(err){
          console.log(err) 
        }
       
              
      }

    })
  },
  toNews:function(event){
    wx.navigateTo({
      url: '/xiaoxi/chat/chat?id='+this.data.teacherUserId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow()
    wx.showToast({
      icon: 'none',
      title: '刷新成功'
    })
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})